#include "login_data.h"

namespace qb
{
	loginData& loginData::instance()
	{
		static loginData sd;
		return sd;
	}

	loginData::loginData()
		: m_connect_id(-1)
		, m_eStatus(eNetStatus_None)
		, m_bReLogin(false)
	{
		ResetLoginData();
	}

	loginData::~loginData()
	{
	}

	tUserData& loginData::UserInfo()
	{
		return m_UserData;
	}

	int32_t& loginData::ConnectID()
	{
		return m_connect_id;
	}

	const tIPAdressPort& loginData::GetServerLoginAddress() const
	{
		return m_serverAddressPort;
	}

	void loginData::SetServerLoginAddress(const std::string& strIP, uint32_t uPort)
	{
		m_serverAddressPort.strIPAdress = strIP;
		m_serverAddressPort.uPort = uPort;
	}

	const tIPAdressPort& loginData::GetGatewayLoginAddress() const
	{
		return m_gatewayAddressPort;
	}

	void loginData::SetGatewayLoginAddress(const std::string& strIP, uint32_t uPort)
	{
		m_gatewayAddressPort.strIPAdress = strIP;
		m_gatewayAddressPort.uPort = uPort;
	}

	NetStatus loginData::GetCurrentStatus() const
	{
		return m_eStatus;
	}

	void loginData::SetCurrentStatus(NetStatus eStatus)
	{
		m_eStatus = eStatus;
	}

	void loginData::SetLoginAck(const xLoginLgnSvrProAck_t& ack)
	{
		m_xLgnAckBody = ack;
	}

	xLoginLgnSvrProAck_t& loginData::GetLoginAck()
	{
		return m_xLgnAckBody;
	}

	void loginData::SetReLogin(bool bReLogin)
	{
		m_bReLogin = bReLogin;
	}

	bool loginData::IsLoggedin() const
	{
		return eNetStatus_Done == GetCurrentStatus();
	}

	bool loginData::IsLoginning() const
	{
		return (eNetStatus_None != GetCurrentStatus() && eNetStatus_Done != GetCurrentStatus());
	}

	bool loginData::IsReLogin() const
	{
		return m_bReLogin;
	}

	void loginData::ResetLoginData()
	{
		ResetLoginAck();
		m_xLgnAckBody.flag = 2;
	}

	void loginData::ResetLoginAck()
	{
		memset(m_xLgnAckBody.cookie, 0, sizeof(m_xLgnAckBody.cookie));
		memset(m_xLgnAckBody.username, 0, sizeof(m_xLgnAckBody.username));
		memset(m_xLgnAckBody.reserve1, 0, sizeof(m_xLgnAckBody.reserve1));
		memset(m_xLgnAckBody.lastip, 0, sizeof(m_xLgnAckBody.lastip));
		memset(m_xLgnAckBody.lastdate, 0, sizeof(m_xLgnAckBody.lastdate));
		memset(m_xLgnAckBody.lasttime, 0, sizeof(m_xLgnAckBody.lasttime));
		memset(m_xLgnAckBody.reserve2, 0, sizeof(m_xLgnAckBody.reserve2));
		memset(m_xLgnAckBody.validtime, 0, sizeof(m_xLgnAckBody.validtime));
		memset(m_xLgnAckBody.userID, 0, sizeof(m_xLgnAckBody.userID));
		m_xLgnAckBody.time = 0;
		m_xLgnAckBody.vid = 0;
		m_xLgnAckBody.utid = 0;
		m_xLgnAckBody.flag = 0;
		m_xLgnAckBody.gwlist.clear();
	}

}  // namespace qb
